package com.syqc.monitor.ui.cost

import com.syqc.comlib.utils.GsonUtil
import com.syqc.entity.DriverVrfInfoFee
import com.syqc.monitor.R
import com.syqc.utils.TimeUtil


class DriverFeeViewModel : BaseFeeViewModel() {
    var driverName: String = ""
    var driverType: String = ""
    var driverCode: String = ""
    var idCard: String = ""
    var annual: String = ""
    var money: String = ""
    var cardDate = TimeUtil.instance.getNowTime(true)
    var feeDate = cardDate

    private var carYearFeeEntity: String = ""
    private var carYearFee: String = ""
    override fun isParamsOk(): Boolean {
        if (driverName.isEmpty()) {
            toast(R.string.hint_toast_driver_name)
            return false
        }
        if (driverType.isEmpty()) {
            toast(R.string.hint_toast_driver_type)
            return false
        }
        if (driverCode.isEmpty()) {
            toast(R.string.hint_toast_driver_code)
            return false
        }
        if (idCard.isEmpty()) {
            toast(R.string.hint_toast_id_card)
            return false
        }
        if (annual.isEmpty()) {
            toast(R.string.hint_toast_year_annual)
            return false
        }
        if (money.isEmpty()) {
            toast(R.string.hint_toast_fee)
            return false
        }

        val entity = DriverVrfInfoFee(
            driverName, driverType, driverCode, idCard, annual, feeDate, cardDate, money, remark
        )
        carYearFee = GsonUtil.toJson(entity)
        if ("$carYearFee$photos" == carYearFeeEntity && isSuccess) {
            toast(R.string.toast_repeat_same_data)
            return false
        }
        carYearFeeEntity = "$carYearFee$photos"
        return true
    }

    fun uploadDriver(){
        if (!isParamsOk())return
        uploadFee("FeeDriverVrf",carYearFee.replace("%","%25"))
    }

    override fun clearData() {
        super.clearData()
        cardDate = TimeUtil.instance.getNowTime(true)
        feeDate = cardDate
    }

}